< previous page page_259 next page >

Page 259
z0279-01.gif
Figure 9.6
Smoothing the values used by tweens can reduce jerkiness.
be the vectors <dx1, dy1> and <dx2, dy2>. Then the coordinates of the points in the Hermite curve between the two endpoints are given by the equations:
e10a6a0a59f035e870d90cca05b85fce.gif
x(t) = x1  *  (2 * t3 - 3 * t2 + 1) + x2  *  (-2  * t3 + 3 * t2) +
       dx1  *  (t
3 - 2 * t2 + t) + dx2  *  (t3 - t2) 
y(t) = y1  *  (2 * t
3 - 3 * t2 + 1) + y2  *  (-2  * t3 + 3 * t2) + 
       dy1  *  (t
3 - 2  * t2 + t) + dy2  *  (t3 - t2)
Here the value t varies from 0 to 1. Figure 9.7 shows two points connected by a Hermite curve. The dashed lines show the tangent vectors at the endpoints.
To create smoothly varying tweens, use these equations with values of t that are multiples of 1/(number of tweens + 1). For example, to create nine tweens, use the values t = 1/10, 2/10, 3/10, . . . , 9/10.
To use the Hermite equations for smooth tweening, you need to pick tangent vectors at the endpoints. Suppose you are connecting the key frame points p1, p2, p3, and p4. To make the curve smooth at the point p2, you need the tangent vector at p2 in the p1p2 curve to be parallel to the tangent vector at p2 in the p2-p3 curve. Figure 9.8 shows this situation.
One way to ensure that the tangents are parallel is to make them parallel to the line connecting the points on either side of the one you are examining. In Figure 9.8, the tangents at point p2 are parallel to the line connecting points p1 and p3.
Example program TweenSmo uses Hermite curves to create smooth tweens. Load the file Square3.twe and create 10 tweens between the key frames. When you run this animation, the motion appears much smoother than it is in program TweenEnd.
Morphing
Tweening is useful for creating frames that fit between key frames. There is no reason you can use tweening only on similar frames. You can also use tweening on two images

 
< previous page page_259 next page >